package com.acceptable.qucun.file.controller;


import com.acceptable.qucun.file.service.FileShareService;
import com.acceptable.qucun.file.service.TemplateFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 巴斯罗斯·K·赫斯洛利
 * @since 2021-08-29
 */
@RestController
@RequestMapping("/share")
public class ShareRestController {

    @Autowired private FileShareService shareService;
    @Autowired private TemplateFileService fileService;

    @PostMapping("/create_share_link")
    public Map<String, Object> createShareLink(@RequestAttribute("data_map") Map<String, String> dataMap){
        return shareService.shareExistedMultiFile(dataMap);
    }

    @GetMapping("/info/{url}/{file_list}")
    public Map<String, Object> shareInfo(@PathVariable("url") String url,
                                         @PathVariable(value = "file_list", required = false) boolean getFileList) {
        return shareService.shareInfo(url, getFileList);
    }

    @PostMapping("/file_list")
    public Map<String, Object> shareFileList(@RequestAttribute("data_map") Map<String, String> dataMap){
        return shareService.shareFileList(dataMap);
    }

    @GetMapping("/info_list/{user_id}")
    public Map<String, Object> shareInfoList(@PathVariable("user_id") Integer userId){
        return shareService.shareInfoList(userId);
    }

    @PostMapping("/save")
    public String saveToDisk(@RequestAttribute("data_map") Map<String, String> dataMap){
        dataMap = shareService.saveSharedFileCheck(dataMap);
        return fileService.copyExistedMultiFile(dataMap);
    }

    @PostMapping("/update")
    public Map<String, Object> updateShareInfo(@RequestAttribute("data_map") Map<String, String> dataMap){
        return shareService.extendSharedInfoLife(dataMap);
    }

    @PostMapping("/cancel")
    public String cancelShare(@RequestAttribute("data_map") Map<String, String> dataMap){
        return shareService.cancelSharedStatus(dataMap);
    }
}

